﻿using System;
using Lypshare.Net;

namespace Lypshare.Flow.Packets
{
	/// <summary>
	/// Raw packet.
	/// </summary>
	/// <exception cref='ArgumentNullException'>
	/// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
	/// </exception>
    public class RawPacket : Packet
    {
        // --------------------------------------------------------
        // Class Properties
        // --------------------------------------------------------


        /// <summary>
        /// Gets or sets the receiver identifier.
        /// </summary>
        /// <value>
        /// The receiver identifier.
        /// </value>
        public int ReceiverId
        {
            get;
            set;

        } // Property: ReceiverId


        /// <summary>
        /// Gets or sets the sender identifier.
        /// </summary>
        /// <value>
        /// The sender identifier.
        /// </value>
        public int SenderId
        {
            get;
            set;

        } // Property: SenderId


        // --------------------------------------------------------
        // Class Functions
        // --------------------------------------------------------


        /// <summary>
        /// Initializes a new instance of the <see cref="Lypshare.Flow.Packets.RawPacket"/> class.
        /// </summary>
        public RawPacket()
        {
        } // Constructor


        /// <summary>
        /// Initializes a new instance of the <see cref="Lypshare.Flow.Packets.RawPacket"/> class.
        /// </summary>
        /// <param name='receiverId'>
        /// Receiver identifier.
        /// </param>
        /// <param name='senderId'>
        /// Sender identifier.
        /// </param>
        public RawPacket(int receiverId, int senderId)
        {
            ReceiverId = receiverId;
            SenderId = senderId;

        } // Constructor


        /// <summary>
        /// Parse the specified buffer.
        /// </summary>
        /// <param name='buffer'>
        /// Buffer.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        protected override void Parse(PacketBuffer buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            ReceiverId = buffer.ReadInt32();
            SenderId = buffer.ReadInt32();
            base.Parse(buffer);

        } // Parse


        /// <summary>
        /// Encode the specified buffer.
        /// </summary>
        /// <param name='buffer'>
        /// Buffer.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        protected override void Encode(PacketBuffer buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            buffer.Write(ReceiverId);
            buffer.Write(SenderId);
            base.Encode(buffer);

        } // Encode

    } // class RawPacket
} // namespace Lypshare.Flow.Packets